package com.junqson.je.content.controller;

import com.junqson.je.common.model.ApiResult;
import com.junqson.je.content.model.ProblemSetModel;
import com.junqson.je.content.model.dto.ProblemDTO;
import com.junqson.je.content.service.ProblemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Descriptions
 * @Company
 * @Author Junqson
 * @Date 2020/2/11 23:10
 * @Version 1.0
 */
@RequestMapping("problem")
@RestController
public class ProblemController {

    @Autowired
    ProblemService problemService;

    // 创建试题集
    @RequestMapping("set/add")
    public ApiResult addProblemSet(@RequestBody ProblemSetModel model) {
        problemService.createProblemSet(model);
        return ApiResult.success();
    }

    // 创建试题
    @RequestMapping("add")
    public ApiResult addProblem(@RequestBody ProblemDTO dto) {
        problemService.createProblem(dto);
        return ApiResult.success();
    }

    //删除试题集
    @RequestMapping("set/del")
    public ApiResult delSet(Long psId) {
        problemService.deletePs(psId);
        return ApiResult.success();
    }

    // 删除试题
    @RequestMapping("del")
    public ApiResult delProblem(Long problemId) {
        problemService.deleteProblem(problemId);
        return ApiResult.success();
    }

    // 获取试题集列表
    @RequestMapping("set/page")
    public ApiResult listPs(Integer page, Integer size) {
        return ApiResult.success(problemService.pageProblemSet(page, size));
    }

    // 获取试题集全部试题
    @RequestMapping("listByPs")
    public ApiResult listByPs(Long psId) {
        return ApiResult.success(problemService.getAllProblems(psId));
    }
}
